﻿package 
{
    import com.core.*;
    import com.sh.game.global.*;
    import control.*;
    import flash.display.*;
    import flash.events.*;
    import flash.system.*;
    import flash.text.*;
    import manager.*;
    import morn.core.components.*;

    public class SctjPlugin extends Object implements IPluginParent
    {
        private var _flashUI:Object;
        private var _flashTips:Object;
        private var _alertCon:Object;
        private var _bindClass:Object;

        public function SctjPlugin(param1:Object)
        {
            this._bindClass = param1;
            return;
        }// end function

        public function init(param1:Object) : void
        {
            this._flashUI = param1.flashUI;
            this._flashTips = param1.flashTips;
            this._alertCon = param1.alertCon;
            ModelProxy.addObserver("key1", Control.create(PluginControl, this));
            this.startPlugin();
            return;
        }// end function

        private function keyDown(event:KeyboardEvent) : void
        {
            var e:* = event;
            try
            {
                if (!this.isFocus)
                {
                    if (Capabilities.hasIME)
                    {
                        if (IME.enabled)
                        {
                            IME.enabled = false;
                        }
                    }
                }
                else if (Capabilities.hasIME)
                {
                    if (IME.enabled == false)
                    {
                        IME.enabled = true;
                        var _loc_3:* = IME;
                        _loc_3.IME["compositionAbandoned"]();
                    }
                }
            }
            catch (error:Error)
            {
            }
            ModelProxy.change("key1", "keyDown1", e);
            ModelProxy.change("key", "down", e);
            return;
        }// end function

        private function startPlugin() : void
        {
            this.createPlugins();
            ModelProxy.change("mainui", "created", null);
            TimeOutManager.getInstance().setTimer(App.gc, 100);
            return;
        }// end function

        public function createPlugins() : void
        {
            var _loc_1:* = PluginManager.instance;
            _loc_1.init(this._bindClass, this._flashUI, this._flashTips, this._alertCon);
            _loc_1.createPluginControl("plugin", PluginControl);
            GlobalLayer.instance.root.addEventListener(KeyboardEvent.KEY_DOWN, this.keyDown);
            GlobalLayer.instance.root.addEventListener(KeyboardEvent.KEY_UP, this.keyUp);
            return;
        }// end function

        private function keyUp(event:KeyboardEvent) : void
        {
            var e:* = event;
            try
            {
                if (!this.isFocus)
                {
                    if (Capabilities.hasIME)
                    {
                        if (IME.enabled)
                        {
                            IME.enabled = false;
                        }
                    }
                }
                else if (Capabilities.hasIME)
                {
                    if (IME.enabled == false)
                    {
                        IME.enabled = true;
                        var _loc_3:* = IME;
                        _loc_3.IME["compositionAbandoned"]();
                    }
                }
            }
            catch (error:Error)
            {
            }
            ModelProxy.change("key1", "keyDown1", e);
            ModelProxy.change("key", "up", e);
            return;
        }// end function

        private function get isFocus() : Boolean
        {
            var _loc_1:* = GlobalLayer.instance.root.focus;
            if (_loc_1 is TextField)
            {
                return TextField(_loc_1).type == TextFieldType.INPUT;
            }
            if (_loc_1 is TextInput)
            {
                return TextInput(_loc_1).editable;
            }
            return false;
        }// end function

    }
}
